#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
#define STACK_INCREMENT 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OVERFLOW -2
typedef int ElemType;
typedef struct 
{
    ElemType * base;
    ElemType * top;
    int stack_size;
}SqStack;
typedef int Status;
Status InitStack(SqStack &S)
{
    S.base = (ElemType*)malloc(sizeof(ElemType) * STACK_INIT_SIZE);
    if (!S.base)
        exit(OVERFLOW);
    S.top = S.base;
    S.stack_size = STACK_INIT_SIZE;
    return OK;
}
Status DestroyStack(SqStack &S)
{
    free(S.base);
    return OK;
}
Status ClearStack(SqStack &S)
{
    S.top = S.base;
    return OK;
}
Status StackEmpty(SqStack S)
{
    if (S.base == S.top)
        return TRUE;
    return FALSE;
}
int StackLength(SqStack S)
{
    return S.top - S.base;
}
Status GetTop(SqStack S, ElemType &e)
{
    if (S.base == S.top)
        return ERROR;
    e = *(S.top - 1);
    return OK;
}
Status Push(SqStack &S, ElemType e)
{
    if (S.top - S.base >= STACK_INIT_SIZE)
    {
        S.base = (ElemType*)realloc(S.base, sizeof(ElemType) * (STACK_INIT_SIZE + STACK_INCREMENT));
        if (!S.base)
            exit(OVERFLOW);
        S.top = S.base + S.stack_size;
        S.stack_size += STACK_INCREMENT;
    }
    *S.top++ = e;
    return OK;
}
Status Pop(SqStack &S, ElemType &e)
{
    if (S.base == S.top)
        return ERROR;
    e = *(--S.top);
    return OK;
}
int main(void)
{
    return 0;
}